﻿using System;
using Best.SmartCms.Domain;
using Best.SmartCms.Dto.File;
using Best.SmartCms.Dto.Enums;
using Best.SmartCms.Service.BizException;
using Best.SmartCms.Service.Common;

namespace Best.SmartCms.Service.Files
{
    public class ExportFileManagerService
    {
        private readonly WorkContext _workContext;
        private readonly MySqlDbContext _mySqlDbContext;
        public string FileMime { get; set; }
        public string FileName { get; set; }

        public ExportFileManagerService(WorkContext workContext, MySqlDbContext mySqlDbContext)
        {
            _workContext = workContext;
            _mySqlDbContext = mySqlDbContext;
        }


        public byte[] Export(ExportFileDto condition)
        {
            if (condition == null || Enum.IsDefined(typeof(ExportFileType), condition.Type) == false)
            {
                throw new ParameterValidationException("未找到指定文件");
            }
            var svc = GetFileService(condition.Type);
            var fileByte = svc.Export(condition.Condition);
            FileMime = svc.FileMime;
            FileName = svc.FileName;
            return fileByte;
        }

        public ExportExcelBaseService GetFileService(ExportFileType fileType)
        {
            switch (fileType)
            {
                default:
                    throw new ObjectNotFoundException(nameof(fileType) + "实现不存在");
            }
        }


    }
}
